
package com.probiz.estoresa.customer.web.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.validation.BindException;
import org.springframework.web.servlet.ModelAndView;

import com.probiz.estore.common.model.product.ProductReview;
import com.probiz.estore.core.controller.GenericStoreAdminController;
import com.probiz.estore.core.search.SearchCriteria;
import com.probiz.estore.product.model.ProductReviewSearchCriteria;
import com.probiz.estore.product.service.ProductReviewManager;

public class ProductReviewReplyController extends GenericStoreAdminController<ProductReview> {
	private ProductReviewManager	productReviewManager	= null;

	public void setProductReviewManager(ProductReviewManager inMgr) {
		this.productReviewManager = inMgr;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.controller.GenericController#getEntityName(java.lang.Object)
	 */
	@Override
	protected String getEntityName(ProductReview entity) {
		return entity.getSubject();
	}


	/*
	 * (non-Javadoc)
	 * 
	 * @see com.probiz.estore.core.controller.BaseController#initController()
	 */
	@Override
	protected void initController() throws Exception {
		mgr = productReviewManager;
	}

	/*
	 * (non-Javadoc)
	 * @see com.probiz.estore.core.controller.GenericStoreAdminController#preSave(javax.servlet.http.HttpServletRequest, java.lang.Object, org.springframework.validation.BindException)
	 */
	@Override
	protected void preSave(HttpServletRequest request, ProductReview entity,
			BindException errors) {
	}
	
	public ModelAndView defaultAction(HttpServletRequest request,
			HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("customer/productReviewReplyList");
		mv.addObject("parentId", request.getParameter("parentId"));
		return mv;
	}
	
	public ModelAndView search(HttpServletRequest request,
			HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("customer/include/productReviewReplyListBody");
		SearchCriteria searchCriteria = createSearchCriteria(request);
		ProductReviewSearchCriteria productReviewSearchCriteria = new ProductReviewSearchCriteria();
		try {
			// 绑定参数
			bind(request, productReviewSearchCriteria);
			List<ProductReview> productReviewList = productReviewManager.searchByCriteriaForController(productReviewSearchCriteria,searchCriteria);
			mv.addObject("productReviewList", productReviewList);
			mv.addObject("productReviewSearchCriteria", productReviewSearchCriteria);
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return mv;
	}
	
	/**
	 * 切换可见隐藏
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView multiToggleReviewShowStatus(HttpServletRequest request,	HttpServletResponse response) {
		String[] ids = request.getParameterValues("multiIds");
		if (ids != null && ids.length > 0) {
			for (String entityId : ids) {
				ProductReview productReview = productReviewManager.getById(Integer.valueOf(entityId));
				if(!productReview.getStatus().equals(ProductReview.STATUS_SHOW)){
					productReviewManager.doMarkShow(productReview);
				}else{
					productReviewManager.doMarkUnShow(productReview);
				}
			}
		}
		return null;
	}
	
	/**
	 * 删除
	 * @param request
	 * @param response
	 * @return
	 */
	public ModelAndView multiDelete(HttpServletRequest request,	HttpServletResponse response) {
		String[] ids = request.getParameterValues("multiIds");
		if (ids != null && ids.length > 0) {
			for (String entityId : ids) {
				ProductReview productReview = productReviewManager.getById(Integer.valueOf(entityId));
				productReviewManager.deleteFully(productReview);
			}
		}
		return null;
	}
	

}
